﻿@namespace MudBlazor
@using MudBlazor.Internal
@using MudBlazor.Resources
@typeparam T
@inherits MudBaseInput<Range<T>>
@inject InternalMudLocalizer Localizer

<div class="@Classname" style="@Style">
    @if (Adornment == Adornment.Start)
    {
        <MudInputAdornment Class="@AdornmentClassname"
                           Icon="@AdornmentIcon"
                           Color="@AdornmentColor"
                           Size="@IconSize"
                           Text="@AdornmentText"
                           Placement="@Adornment.Start"
                           AdornmentClick="@OnAdornmentClick"
                           AriaLabel="@AdornmentAriaLabel" />
    }

    @if (InputType == InputType.Hidden && ChildContent != null)
    {
        <div class="@InputClassname">
            @ChildContent
        </div>
    }

    <input @ref="_elementReferenceStart"
           @attributes="UserAttributes"
           type="@InputTypeString"
           class="@InputClassname"
           @bind-value="@TextStart"
           @bind-value:event="@(Immediate ? "oninput" : "onchange")"
           placeholder="@PlaceholderStart"
           disabled="@GetDisabledState()"
           readonly="@GetReadOnlyState()"
           @onblur="@OnBlurredAsync"
           @onkeydown="@InvokeKeyDownAsync"
           @onkeyup="@InvokeKeyUpAsync"
           inputmode="@InputMode.ToDescriptionString()"
           pattern="@Pattern"
           required="@Required"
           aria-required="@Required.ToString().ToLowerInvariant()" />
    <MudIcon Class="mud-range-input-separator mud-flip-x-rtl" Icon="@SeparatorIcon" Color="@Color.Default" />
    <input @ref="_elementReferenceEnd"
           @attributes="UserAttributes"
           type="@InputTypeString"
           class="@InputClassname"
           @bind-value="@TextEnd"
           @bind-value:event="@(Immediate ? "oninput" : "onchange")"
           inputmode="@InputMode.ToDescriptionString()"
           pattern="@Pattern"
           placeholder="@PlaceholderEnd"
           disabled="@GetDisabledState()"
           readonly="@GetReadOnlyState()"
           @onblur="@OnBlurredAsync"
           @onkeydown="@InvokeKeyDownAsync"
           @onkeyup="@InvokeKeyUpAsync"
           required="@Required"
           aria-required="@Required.ToString().ToLowerInvariant()" />

    @if (IsClearable() && !GetDisabledState())
    {
        <MudIconButton Class="@ClearButtonClassname" Style="z-index: 2"
                       Color="@Color.Default"
                       Icon="@Icons.Material.Filled.Clear"
                       Size="@Size.Small"
                       OnClick="@ClearButtonClickHandlerAsync"
                       aria-label="@Localizer[LanguageResource.MudInput_Clear]"
                       tabindex="-1" />
    }

    @if (Adornment == Adornment.End)
    {
        <MudInputAdornment Class="@AdornmentClassname"
                           Icon="@AdornmentIcon"
                           Color="@AdornmentColor"
                           Size="@IconSize"
                           Text="@AdornmentText"
                           Placement="@Adornment.End"
                           AdornmentClick="@OnAdornmentClick"
                           AriaLabel="@AdornmentAriaLabel" />
    }

    @if (Variant == Variant.Outlined)
    {
        <div class="mud-input-outlined-border"></div>
    }
</div>